<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form action="#">
        <div>
            用户名:
            <input type="text" name="" id="">
        </div>
        <div>
            密&nbsp&nbsp 码:
            <input type="password" name="" id="firstInput">
        </div>
        <div>
            确认密码:
            <input type="password" name="" id="secondInput" onblur="save()">
        </div>
    </form>


    <script>
        var firstInput = document.querySelector('#firstInput')
        var secondInput = document.querySelector('#secondInput')
        function save() {
            if (firstInput.value !== secondInput.value) {
                alert('两次输入的密码不一致')
            }
        }

    </script>
</body>

</html>